<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
 |
 | Flash Helper by Khoiruddin - http://khoiruddin.com
 | Modified from https://github.com/obxhdx/codeigniter-flash-helper
 |
 */

/**
 * Display all flash message.
 *
 * @access public
 * @return string
 */

function display_flash(){
  $flash = display_each_flash('success');
  $flash .= display_each_flash('info');
  $flash .= display_each_flash('warning');
  $flash .= display_each_flash('danger');

  return $flash;
}

/**
 * Display each formatted flash message.
 *
 * @access public
 * @param string|array
 * @return string
 */

function display_each_flash($message_type)
{
  $CI =& get_instance();
  if($CI->session->flashdata($message_type))
  {
    $flash = $CI->session->flashdata($message_type);
    if (is_array($flash['message'])) {
      $msg = null;
      foreach ($flash['message'] as $flash_message) {
        $msg .= '<div class="alert alert-' . $message_type . '">' . $flash_message . '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button></div>';
      }
      return $msg;
    } else {
      return '<div class="alert alert-' . $message_type . '">' . $flash['message'] . '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button></div>';
    }
  }
}

/**
 * Save provided message as a flash variable.
 *
 * @access public
 * @param string
 * @param string
 * @param boolean
 */
function set_flash($message_type, $message, $redirect=FALSE)
{
  $CI =& get_instance();
  $CI->session->set_flashdata($message_type, array('message' => $message));
  if ($redirect)
    redirect($redirect);
}
/* End of file flash_helper.php */
/* Location: ./application/helpers/flash_helper.php */